<template>
<view v-if="showuid" :style="theme" class="page">
	
	<!--设置-->
	<view class="d-kuan">
		<view class="d-neikuang-10 ">
			<view class="d-kuan d-yuanjiao-10 d-beijing-bai">
				<view class="d-neikuang-10">
					<u--form
						labelPosition="left"
						:model="ziliao"
						:rules="rules"
						ref="uForm"
					>
					    <u-form-item
							label="昵称"
							prop="ziliao.nicheng"
							borderBottom
							ref="item1"
						>
							<u--input
								v-model="ziliao.nicheng"
								border="none"
								:value="ziliao.nicheng"
								color="#ee0000"
							></u--input>
						</u-form-item>
					</u--form>
				</view>
			</view>
			<u-button class="d-shang-20" @click="d_ziliao" type="primary" size="large" text="提 交 修 改"></u-button>
		</view>
	</view>
	
	
	<!-- 版权信息template模板 -->
	<view class="copyright" >
		<block data-type="template" data-is="tempCopyright" data-attr="webSiteName:webSiteName,domain:domain">
			<view> {{webSiteName}} </view>
			<view> {{banbenhao}} </view>
		</block>
	</view>
	
</view>
<view v-else>
	<view class="d-kuan d-neikuang-10">
		
		<view class="u-content">
			<view class="u-content__circle">
				<u-icon
					name="checkbox-mark"
					color="#fff"
					size="30"
				></u-icon>
			</view>
			<text class="u-content__normal">跳转登录</text>
		</view>
	</view>
</view>
</template>

<script>

var Api = require("../../utils/api.js");
var util = require("../../utils/util.js");

var wxApi = require("../../utils/wxApi.js");
var wxRequest = require("../../utils/wxRequest.js");
import config from "../../utils/config";
var pageCount = config.getPageCount;
var webSiteName = config.getWebsiteName;
var domain = config.getDomain;
var banbenhao = config.getDuixinbanbenhao;
const app = getApp();
/*#ifdef APP-PLUS || H5*/
	var code = uni.getStorageSync('userInfo');
/*#endif*/
/*#ifdef MP-WEIXIN*/
    var code = uni.getStorageSync('userInfo');
/*#endif*/

export default {
  data() {
    return {
      isArticlesList: true,
      listStyle: config.getListStyle,
      shareTitle: config.getWebsiteName,
      pageTitle: '我的',
      articlesList: [],
	  yonghuXinxi: [],
      postype: "post",
      webSiteName: webSiteName,
	  banbenhao: banbenhao,
      domain: domain,
	  member: [],
	  code:code,
	  show: false,
	  showuid: false,
	  ziliao: {
		  nicheng:''
	  },
	  rules: {
			'ziliao.nicheng': {
				type: 'string',
				required: true,
				message: '请填写修改昵称',
				trigger: ['blur', 'change']
			}
		},
		wouid:'',
		wocode:'',
		fenggeyanse:''
    };
  },

  components: {},
  props: {},
  onShow: function () {

	// 暗黑模式
	var duixin = this;
	var initialThemes = uni.getStorageSync('theme');
	duixin.fenggeyanse = initialThemes;
	uni.setNavigationBarColor({
		backgroundColor: this.fenggeyanse =='light'? '#ffffff':'#151515',
		frontColor: this.fenggeyanse =='light'? '#000000':'#ffffff',
	})
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
	  var duixin = this; 

	uni.reLaunch();
	  
	  
	    
	//判断用户是否登录
	var userInfo = uni.getStorageSync('userInfo');
	
	if (userInfo) {
		this.showuid = true;
		var member = uni.getStorageSync('member');
		var memberuid = uni.getStorageSync('memberuid');
		//console.log("member1",member);
		//console.log("userInfo1",userInfo);
		duixin.getZiliaos(memberuid,userInfo);

		duixin.wouid = memberuid;
		duixin.wocode = userInfo;

		// 保留二次开发
		duixin.getYonghuXinxi(memberuid);
	} else {
		//否则跳转到登录页面
		uni.reLaunch({ url: '/pages/login/login'}) // 跳转到首页
	}
	
    var postype = 'post';

    if (options.postype) {
      postype = options.postype;
    }
	
    this.setData({
      postype: postype
    });
  },
  onReady: function () {
    uni.setNavigationBarTitle({
      title: this.pageTitle
    });
  },
  methods: {
	bangdingYicun(){
		uni.navigateTo({
		  url: '/pages/wo/xiaochengxuguanli',
		  
		});
		console.log('open');
	},
	open() {
	// console.log('open');
	},
	close() {
	this.show = false
	// console.log('close');
	},
	//会员信息
	getYonghuXinxi(uid) {
		var self = this; 
		self.setData({
		  yonghuXinxi: []
		});
		
		var getYonghuXinxiRequest = wxRequest.getRequest(Api.getYonghuXinxi(uid));
		getYonghuXinxiRequest.then(response => {
			if (response.data.code == 1) {
			  
			  self.yonghuXinxi = response.data.data;
			  self.ziliao.nicheng = response.data.data.name;
			} else {
			  self.setData({
				displaySwiper: "none"
			  });
			}
		});
	},
	//获取个人资料
	getZiliaos(uid,code) {
		var duixin = this; 
		duixin.setData({
		  //ziliao: {},
		});
		var postZiliaoRequest = wxRequest.getRequest(Api.postZiliao(uid,code));
		postZiliaoRequest.then(response => {
			if (response.data.code == 1) {
			  
			  //duixin.ziliao = response.data.data.list;
			  
			  
			} else {
			  duixin.setData({
				displaySwiper: "none"
			  });
			}
		});
	},

	exitlogin() {
		uni.removeStorageSync('userInfo');
		uni.removeStorageSync('memberuid');
		uni.reLaunch({ url: '/pages/login/login'})
	},

	click(e){
		console.log("e",e)
	},
	d_ziliao() {
		var duixin = this;
		var nicheng = duixin.ziliao.nicheng;
		var uid = duixin.wouid;
		var code =duixin.wocode;
		var datas = "&is_ajax=1&data[name]="+nicheng;
		var postRenzhengRequest = wxRequest.postRequest(Api.postZiliao(uid,code),datas);
			postRenzhengRequest.then(response => {
				if (response.data.code == 1) {
					duixin.getYonghuXinxi(uid);
					uni.showToast({
						title: response.data.msg,
						icon: 'success',
						success: function () {
						}
					});
				} else {
					uni.showToast({
						title: response.data.msg,
						icon: 'error',
					});
				}
			});
	}
	
  }
};
</script>
<style lang="scss">
@import "./shezhi.css";
page {
	background-color: var(--nav-color-bg);
}
</style>